﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_SFSQControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        TextBox txtCaseid, txtID, txtSQYY;
        MPCalendar txtSFSQ;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            string strid = base.Page.Request["ID"];
            string strcaseid = base.Page.Server.UrlDecode(base.Page.Request["caseid"]); 
            if (string.IsNullOrEmpty(strcaseid))
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("案件号未填写！", "window.close();");
            }
            if (!base.Page.IsPostBack)
            {
                if (!string.IsNullOrEmpty(strcaseid)) { txtCaseid.Text = strcaseid; }
                if (!string.IsNullOrEmpty(strid)) { 
                    txtID.Text = strid;
                    DataTable dt = _EluZSDataProvider.GetTable("select * from ZS_SFSQXX where id='" + strid + "'");
                    if (dt.Rows.Count > 0) {
                        txtCaseid.Text = dt.Rows[0]["CASEID"].ToString();
                        txtSQYY.Text = dt.Rows[0]["SQYY"].ToString();
                        txtSFSQ.Text = dt.Rows[0]["SQRQ"].ToString();
                    }
                }
            }

            Button btn_Insert = (Button)FindControl("btn_Insert");
            btn_Insert.Click += new EventHandler(btn_Insert_Click);
        }
        protected void InitControl() {
            txtCaseid = (TextBox)FindControl("txtCaseid");
            txtID = (TextBox)FindControl("txtID");
            txtSQYY = (TextBox)FindControl("txtSQYY");
            txtSFSQ = (MPCalendar)FindControl("txtSFSQ");
        }
        protected void btn_Insert_Click(object sender, EventArgs e)
        {
            string strid = base.Page.Request["ID"];
            string strNewId = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper();
            string strCASEID = txtCaseid.Text;
            string strSFSQ = txtSFSQ.Text;
            string strSQYY = txtSQYY.Text;

            base.Page.Session["nCount"] = "8";
            string sql = @"Update zs_sfsqxx Set CASEID='" + strCASEID + "',SQYY='" + strSQYY + "',SQRQ=to_date('" + strSFSQ + "','yyyy-MM-dd hh24:mi:ss') Where Id='" + strid + "'";
            if (string.IsNullOrEmpty(strid))
            {
                sql = "Insert Into zs_sfsqxx (Id,caseid,sqyy,sqrq) Values ('" + strNewId + "','" + strCASEID + "','" + strSQYY + "',to_date('" + strSFSQ + "','yyyy-MM-dd hh24:mi:ss'))";
            }
            _EluZSDataProvider.RunSqlNon(sql);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptbasic1", "<script>windowClose('" + base.Page.Request["type"] + "');</script>");
        }
    }
}


